package com.business.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.business.common.annotation.Log;
import com.business.common.core.controller.BaseController;
import com.business.common.core.domain.AjaxResult;
import com.business.common.enums.BusinessType;
import com.business.exam.domain.ExamQbQuestions;
import com.business.exam.service.IExamQbQuestionsService;
import com.business.common.utils.poi.ExcelUtil;
import com.business.common.core.page.TableDataInfo;

/**
 * 题库Controller
 *
 * @author zhanglele
 * @date 2023-12-04
 */
@RestController
@RequestMapping("/questionbank/questions")
public class ExamQbQuestionsController extends BaseController
{
    @Autowired
    private IExamQbQuestionsService examQbQuestionsService;

    /**
     * 查询题库列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:questions:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamQbQuestions examQbQuestions)
    {
        startPage();
        List<ExamQbQuestions> list = examQbQuestionsService.selectExamQbQuestionsList(examQbQuestions);
        return getDataTable(list);
    }

    /**
     * 导出题库列表
     */
   // @PreAuthorize("@ss.hasPermi('questionbank:questions:export')")
    @Log(title = "题库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQbQuestions examQbQuestions)
    {
        List<ExamQbQuestions> list = examQbQuestionsService.selectExamQbQuestionsList(examQbQuestions);
        ExcelUtil<ExamQbQuestions> util = new ExcelUtil<ExamQbQuestions>(ExamQbQuestions.class);
        util.exportExcel(response, list, "题库数据");
    }

    /**
     * 获取题库详细信息
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:questions:query')")
    @GetMapping(value = "/{qbMainId}")
    public AjaxResult getInfo(@PathVariable("qbMainId") Long qbMainId)
    {
        return success(examQbQuestionsService.selectExamQbQuestionsByQbMainId(qbMainId));
    }

    /**
     * 新增题库
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:questions:add')")
    @Log(title = "题库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamQbQuestions examQbQuestions)
    {
        return toAjax(examQbQuestionsService.insertExamQbQuestions(examQbQuestions));
    }

    /**
     * 修改题库
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:questions:edit')")
    @Log(title = "题库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamQbQuestions examQbQuestions)
    {
        return toAjax(examQbQuestionsService.updateExamQbQuestions(examQbQuestions));
    }

    /**
     * 删除题库
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:questions:remove')")
    @Log(title = "题库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{qbMainIds}")
    public AjaxResult remove(@PathVariable Long[] qbMainIds)
    {
        return toAjax(examQbQuestionsService.deleteExamQbQuestionsByQbMainIds(qbMainIds));
    }
}
